<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/themes/bootstrap/easyui.css" />
<link type="text/css"
	href="${pageContext.request.contextPath}/themes/icon.css"
	rel="stylesheet">
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/jquery-1.9.1.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/easyui-lang-zh_CN.js"></script>
<title>员工信息管理</title>
</head>
<script type="text/javascript">
$(function(){
	$('#tab').datagrid({    
	    url:'showTable',    
	    rownumbers:true,
	    columns:[[   
	        {field:'checkbox',checkbox:true},
	        {field:'eId',title:'id',width:100,hidden:true},    
	        {field:'eAccount',title:'员工登陆账号',width:300}, 
	        {field:'ePsw',title:'员工登陆密码',width:300},  
	        {field:'eName',title:'员工姓名',width:300},  
	        {field:'rName',title:'员工职责',width:300},  
	     ]] , 
	        pagination:true,
		    pagePosition:'bottom',
			pageSize:3,
			pageList:[15,20],
	        toolbar: [{
		    iconCls: 'icon-add',
		    text:'添加员工',
		    handler: function(){
			$('#inputIn').window('open',{
			});  
			//分别清除框中各项的值
			$('#ipAccount').textbox('clear',true);	
			$('#ipPsw').textbox('clear',true);	
		    $('#ipName').textbox('clear',true);	
			$('#iprName').combobox('clear',true);	
		}     
	    },'-',{
		iconCls: 'icon-edit',
		text:'修改信息',
		handler: function(){
		var upGet=$('#tab').datagrid('getSelections');   
		if(upGet.length==1){
			//弹出修改框
			$('#inputUp').window('open',{
			}); 
			//获取表中的值(得到值)
	 var v= $("#ipeId1").textbox('setValue',upGet[0].eId);
	  $("#ipAccount1").textbox('setValue',upGet[0].eAccount);
	  $("#ipPsw1").textbox('setValue',upGet[0].ePsw);
	  $("#ipName1").textbox('setValue',upGet[0].eName);
	  $("#iprName1").combobox('setValue',upGet[0].rName);
		}else if(upGet.length>1){
			$.messager.confirm('提示 ','请选择一个修改项')
		}else{
			$.messager.confirm('提示 ','请选择需要修改的项');  
		}
		}
	},'-',{
		iconCls: 'icon-cancel',
		text:'注销员工',
		handler: function(){
			var del=$('#tab').datagrid('getSelections'); 
	     if(del.length==0){
	    	 $.messager.alert('提示','请选择需要删除的项','info');    
	     }else{
	    	 $.messager.confirm('确认','您确认想要删除所选项吗？',function(r){    
	    		    if (r){    
	    		    	var a=[];
	    		    	 $.each(del,function(i,n){
	    		    		     var eid=n.eId;
	    		    		     a.push(eid);
	    		    		});
	    		    	 console.log(a);
	    			     $.ajax({
	    			    	url:'deletEmployee',
	    			    	traditional:true,
	    			    	type:'post',
	    			    	data:{'eid2':a},
	    			         dataType:'json',
	    			       success:function(dele){
	    			         if(dele="1"){
	    			        	 $.messager.alert('正确提示','成功删除成员','info');
	    			        	
	    			         }else{
	    			        	 $.messager.alert('错误提示','删除失败！','info');
	    			         }
	    			         $("#tab").datagrid('reload');
	    			      }
	    			    })
	    		    }else{
	    		    	$('#tab').datagrid('clearSelections');
	    		    }
	    		    
	    		});  
	     }
		}
	},'-',{
		iconCls: 'icon-search',
		text:'查询',
		handler: function(){
			$('#select').window('open',{
			}); 
		}
	}],
	});
	//下拉菜单
	$('#iprName').combobox({    
	    url:'showrName',    
	    valueField:'rid',    
	    textField:'rtext',
	    lines:true,
	    panelHeight:'auto',
	    editable:false,
	}); 	
	$('#iprName1').combobox({    
	    url:'showrName1',    
	    valueField:'rid1',    
	    textField:'rtext1',
	    lines:true,
	    panelHeight:'auto',
	    editable:false,
	}); 	
	//
	// 确认添加按钮
	$('#btnIn').bind('click', function(){ 
		//获取输入框中的值
	        var account=$("#ipAccount").val();
			 var psw=$("#ipPsw").val();
			 var name=$("#ipName").val();
		      var rname=$("#iprName").combobox('getValue');
			 $.ajax({
	        	 url:'insertEmployee',
	        	 type:'post',
	        	 data:{'eAccount':account,'ePsw':psw,'eName':name,'rname':rname},
	      	 	 dataType:'json',
	      		 success:function(insert){
	      			 if(insert=="1"){
	      				$.messager.alert('提示','成功添加员工！','info');
	      			 }else{
	      				$.messager.alert('提示','添加失败！','info');
	      			 }
	      			 $('#tab').datagrid('reload'); 
	      			 $('#inputIn').window("close");	
	          } 
		 })

	    });
	//取消添加按钮 
	$('#btnIn2').bind('click', function(){ 
		 $('#inputIn').window("close");
	})
	//
	//确认修改按钮 
	  $('#btnUp').bind('click', function(){
		  var eid1=$("#ipeId1").val();
		  var account1=$("#ipAccount1").val();
	  	 var psw1=$("#ipPsw1").val();
	     var name1=$("#ipName1").val();
		  var rname1=$("#iprName1").combobox('getValue');
		  $.ajax({
	        	 url:'updateEmployee',
	        	 type:'post',
	        	 data:{'eAccount1':account1,'ePsw1':psw1,'eName1':name1,'rname1':rname1,'eId1':eid1},
	      	 	 dataType:'json',
	      		 success:function(update){
	      			 if(update=="1"){
	      				$.messager.alert('提示','修改信息成功！','info');
	      			 }else{
	      				$.messager.alert('提示','修改信息失败！','info');
	      			 }
	      			$('#tab').datagrid('reload'); 
	            } 
		  })  
		  $('#inputUp').window("close");
	  }) 
	  //取消修改按钮
	  $('#btnUp2').bind('click', function(){  
		 $('#inputUp').window("close");
		 $('#tab').datagrid('clearSelections');
	})
	//确认查询 
	$("#btnSel").bind('click', function(){ 
		$("#select").window("close");
		var text=$("#insel").val();
		  $('#tab').datagrid({    
		    url:'selectEmployee',    
		    rownumbers:true,
		    checkbox:true,
		    columns:[[   
		        {field:'checkbox',checkbox:true},
		        {field:'eId',title:'id',width:100,hidden:true},    
		        {field:'eAccount',title:'员工登陆账号',width:300}, 
		        {field:'ePsw',title:'员工登陆密码',width:300},  
		        {field:'eName',title:'员工姓名',width:300},  
		        {field:'rName',title:'员工职责',width:300},   
		     ]] , 
		        pagination:true,
			    pagePosition:'bottom',
				pageSize:3,
				pageList:[5,8],
				queryParams:{'val':text}
		})
		  $("#insel").textbox('clear');  
	})
})
</script>
<body>
<div>
<table id="tab">
</table>
<table id="sele">
</table>
<!-- ----------------添加员工信息--------------- -->
<div id="inputIn" class="easyui-window" data-options="closed:true" style="width:400px;height:350px">
 <div id="di" style="padding:10% 10% ">
 <span>员工账号：</span><input id="ipAccount" type="text" class="easyui-textbox"/><br/><br/>
 <span>员工密码：</span><input id="ipPsw" type="text" class="easyui-textbox"/><br/><br/>
 <span>员工姓名：</span><input id="ipName" type="text" class="easyui-textbox"/><br/><br/>
<span>员工职责：</span><input id="iprName" class="easyui-combobox" name="dept" style="margin-left:30px"/>
</div>
<div style="margin-left:18%;padding-bottom:10%">
 <a id="btnIn" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-ok'">确认添加</a>  
  &nbsp;&nbsp;&nbsp;&nbsp;<a id="btnIn2" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-no'">取消添加</a>  
</div>
</div>
<!------------------ 修改员工信息------------------- -->
<div id="inputUp" class="easyui-window" data-options="closed:true" style="width:400px;height:350px">
 <div id="di" style="padding:10% 10% ">
 <div style="display:none">
 <input id="ipeId1" type="text" class="easyui-textbox"  />
 </div>
 <span>员工账号：</span><input id="ipAccount1" type="text" class="easyui-textbox"/><br/><br/>
 <span>员工密码：</span><input id="ipPsw1" type="text" class="easyui-textbox"/><br/><br/>
 <span>员工姓名：</span><input id="ipName1" type="text" class="easyui-textbox"/><br/><br/>
<span>员工职责：</span><input id="iprName1" name="dept1" class="easyui-combobox" style="margin-left:30px"/>
</div>
<div style="margin-left:18%;padding-bottom:10%">
 <a id="btnUp" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-ok'">确认修改</a>  
  &nbsp;&nbsp;&nbsp;&nbsp;<a id="btnUp2" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-no'">取消修改</a>  
</div>
</div>

<div id="select" class="easyui-window" data-options="closed:true" title="查询员工信息" minimizable=false maximizable=false style="width:300px;height:160px">
  <div id="div1" style="margin-top:25px;margin-left:40px">
  <input id="insel" type="text" class="easyui-textbox" prompt="请输入查询信息,比如：姓名" style="width:210px;height:30px'"/><br/><br/>
   <div style="margin-left:50px"><a id="btnSel" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'" style="align:center">点击查询</a></div>
 </div> 
 <div id="sel" class="easyui-window" data-options="closed:true" style="width:600px;height:500px">
 
 </div>
</div>
</div>
</body>
</html>